/*
 * Amkai Enterprise Solution (AES.) 
 * Copyright 2004 by Amkai(TM), Inc.
 * www.amkai.com
 * 
 * Project: webservice
 * Package: com.amkai.aes.webservice.binary.objecthandler
 * File: PersonRelaionshipsHandler.java
 * Created: Feb 27, 2006 11:31:08 AM
 * Author: johnny 
 * 
 */
package com.amkai.aes.webservice.binary.objecthandler;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.amkai.aes.aescommon.service.binary.job.PersonRelationshipsJob;
import com.amkai.aes.aescommon.service.result.PersonUniqueResult;
import com.amkai.aes.server.registration.relationship.PersonRelationshipSearch;
import com.amkai.aes.webservice.binary.JobObjectHandler;
import com.amkai.common.extensions.hibernate.config.SiteManager;
import com.amkai.common.extensions.hibernate.config.manager.SessionManager;

/**
 * PersonRelaionshipsHandler
 * @author johnny
 * Description:
 *
 */
public class PersonRelaionshipsHandler implements JobObjectHandler<PersonRelationshipsJob, Serializable, PersonUniqueResult> {
	private static final Log log = LogFactory.getLog(PersonRelaionshipsHandler.class);

	
	public PersonUniqueResult process(PersonRelationshipsJob job, Serializable object) throws Exception {
		SessionManager sm = SiteManager.Start();
		try {
			sm.openSession();
			List<Object[]> list = PersonRelationshipSearch.getPersonRelationships(sm, job.getPersonId());
			PersonUniqueResult result = new PersonUniqueResult();
			result.setDatas(PersonRelationshipSearch.convertListToArray(list));
			return result;
		}
		catch (Exception ex) {
			log.error("",ex);
			throw ex;
		}
		finally {
			sm.closeSession();
		}
	}

}
